package ControlLayer;
import ModelLayer.*;
import java.util.ArrayList;


//model layer package has to be imported

/**
 * Controller class for the address book
 * 
 * @author (Group1:Georgi,Roland and Mindaugas) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    
    private AddressBook book;
    
    
    public AddressCtr()
    {
        book = AddressBook.getAddressBook();
    }
    
    /**
     * Calls the method in model layer addressbook checking i a person exists.
     */
    public boolean personExist(long id)
    {
      return book.personExist(id);
    }
    
    /**
     * Sends a command to the model layers address book to search for a person using its ID and calls its accesor methods.
     */
    public String getPersonName(long id)
    {
        return book.searchPerson(id).getName();
        
    }
    
        public String getPersonAddress(long id)
    {
        return book.searchPerson(id).getAddress();
        
    }
    
        public String getPersonPostalCode(long id)
    {
        return book.searchPerson(id).getPostalCode();
        
    }
    
        public String getPersonCity(long id)
    {
        return book.searchPerson(id).getCity();
        
    }
    
        public String getPersonPhone(long id)
    {
        return book.searchPerson(id).getPhone();
        
    }
    
    /**
     * calls the create person method from the control layer AddressBook class.
     */
    public void createPerson(long id, String name, String address, String postalCode, String city, String phone)
    {   
        book.createPerson(id, name, address, postalCode, city, phone);
    }
    
    /**
     * calls the delete person method from the control layer AddressBook class.
     */
    public void deletePerson(long id)
    {
       book.deletePerson(id);
    }
    
    /**
     * Updates the Persons details.
     */
    public void updatePerson(long id, String name, String address, String postalCode, String city, String phone)
    {
        updatePersonName( id, name);
        updatePersonAddress( id, address);
        updatePersonPostalCode( id, postalCode);
        updatePersonCity( id, city);
        updatePersonPhone(id,phone);
        
    }
    
    /**
     * Searches a person using its id through the model layers Address Book and calls its Mutator Methods.
     */
    public void updatePersonName(long id, String name)
    {
        book.searchPerson(id).setName(name);
    }
    
    public void updatePersonAddress(long id, String address)
    {
        book.searchPerson(id).setAddress(address);
    }
    
    public void updatePersonPostalCode(long id, String postalCode)
    {
        book.searchPerson(id).setPostalCode(postalCode);
    }
    
    public void updatePersonCity(long id, String city)
    {
        book.searchPerson(id).setCity(city);
    }
    
    public void updatePersonPhone(long id, String phone)
    {
        book.searchPerson(id).setPhone(phone);
    }
    
    /**
     * Sends a command to the model layers Address Book and calls the Accesor methods that return information about all persons.
     */
    
    public ArrayList<String> getPersonsNames()
    {
       return book.getPersonsNames();
       
    }
    
    public ArrayList<String> getPersonsAddress()
    {
       return book.getPersonsAddress();
       
    }
    
     public ArrayList<String> getPersonsPostalCodes()
     {
          return book.getPersonsPostalCodes();
     }
    
    public ArrayList<String> getPersonsCities()
    {
        return book.getPersonsCities();
    }
    
    public ArrayList<String> getPersonsPhones()
    {
        return book.getPersonsPhones();
    }
    
    public ArrayList<Long> getPersonsIDs()
    {
        return book.getPersonsIDs();
    }
}
